const { exec } = require('child_process');

// 定义时间范围
// const since = '2025-01-01';
// const until = '2025-01-31';
const since = '2025-02-01';
const until = '2025-02-28';

// 执行 git log 命令
const command = `git log --since=${since} --until=${until} --pretty=tformat: --numstat`;
exec(command, (error, stdout, stderr) => {
  if (error) {
    console.error(`Error: ${error.message}`);
    return;
  }
  if (stderr) {
    console.error(`Stderr: ${stderr}`);
    return;
  }

  // console.log('stdout',stdout);
  
  // 处理 git log 输出
  const lines = stdout.split('\n');
  let add = 0, subs = 0, loc = 0;

  lines.forEach(line => {
    const [added, removed] = line.split('\t');
    if (added && removed) {
      add += parseInt(added, 10) || 0;
      subs += parseInt(removed, 10) || 0;
      loc += (parseInt(added, 10) || 0) - (parseInt(removed, 10) || 0);
    }
  });

  // 输出结果
  console.log(`Added lines: ${add}, Removed lines: ${subs}, Total lines: ${loc}`);
});